package com.linan.base.service.impl;


import com.linan.base.mapper.BaseMapper;
import com.linan.base.domain.PageList;
import com.linan.base.query.BaseQuery;
import com.linan.base.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;
    @Override
    public void save(T t) {
        System.out.println(1111111);
        mapper.save(t);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public void delete(Long id) {
        mapper.remove(id);
    }

    @Override
    public T getById(Long id) {
        return mapper.loadById(id);
    }

    @Override
    public List<T> getAll() {
        return mapper.loadAll();
    }

    @Override
    public PageList<T> queryData(BaseQuery query) {
        Long total = mapper.queryCount(query);
        if(total==null||total<1){
            return  new PageList<T>();
        }
        List<T> data = mapper.queryData(query);
        return  new PageList<T>(total,data);
    }
}


